package org.yefei.homeworkday26;

import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class TestCompany {

	public static void main(String[] args) {
		int choice = 0;

		Company com = null;
		ObjectInputStream k = null;
		Scanner in = new Scanner(System.in);
		//

		try {
			FileInputStream fin = new FileInputStream("F:\\叶飞io测试\\IOhomework测试\\info.txt");
			k = new ObjectInputStream(fin);
			com = (Company) k.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (k != null)
				try {
					k.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
		// 创建对象
		if (com == null) {
			System.out.println("请输入公司名：");
			String na = in.next();
			System.out.println("请输入公司注册地址：");
			String ad = in.next();
			System.out.println("请输入公司的电话：");
			String ph = in.next();
			System.out.println("请输入公司经营范围：");
			String ra = in.next();
			com = new Company(na, ad, ph, ra);
		}
		ComThread c = new ComThread(com);
		c.start();
		while (true) {
			com.showCompany();
			System.out.println("1:招新员工，2：查看员工信息，3：辞退员工，4:统计公司人数，9：退出");
			choice = in.nextInt();
			if (choice == 1) {
				Staff st = new Staff();
				System.out.println("新员工工号：");
				String cn = in.next();
				st.setwNum(cn);
				System.out.println("新员工姓名：");
				String n = in.next();
				st.setName(n);
				System.out.println("新员工年龄：");
				int a = in.nextInt();
				st.setAge(a);
				System.out.println("新员工性别：");
				String s = in.next();
				st.setSex(s);
				System.out.println("新员工职务：");
				String p = in.next();
				st.setPosition(p);
				System.out.println("新员工薪水：");
				double sala = in.nextDouble();
				st.setSalary(sala);
				com.addNewStaff(st);
			} else if (choice == 2) {
				com.printStaff();
			} else if (choice == 3) {
				System.out.println("辞退员工的工号：");
				String yNum = in.next();
				com.fireStaff(yNum);
			} else if (choice == 4) {
				com.cal();
			} else if (choice == 9) {
				System.out.println("退出系统！");
				break;
			} else {
				System.out.println("输入有误！重新输入：");
			}
		}
	}

}
